package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    //品牌管理分页列表
    @GetMapping("{page}/{limit}")
    public Result getTrademarkList(@PathVariable long page,
                                   @PathVariable long limit){
        Page<BaseTrademark> page1 = new Page<>(page,limit);
       IPage  trademarkList=baseTrademarkService.getTrademarkList(page1);
       return Result.ok(trademarkList);
    }

    //品牌保存
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark){
         baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    //品牌删除
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable long id){
        baseTrademarkService.removeById(id);
        return Result.ok();
    }

    //根据id获取品牌详情
    @GetMapping("get/{id}")
    public Result getTrademark(@PathVariable long id){
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        return Result.ok(baseTrademark);
    }

    //品牌修改
    @PutMapping("update")
    public Result update(@RequestBody BaseTrademark baseTrademark){
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }




}
